package com.totsp.conference;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.totsp.conference.data.DataHelper;
import com.totsp.conference.data.Presentation;

public class OldMain extends ConfActivity implements OnClickListener {

	// NOTE - this is *not* the best way to do a complex clickable TableLayout
	// like this - this is the quick and dirty (temp) way
	// rather the table could be be programatically (instead of with a layout
	// xml file) and the data could come from a database
	// different "rows" could expand and shrink as needed as indicated by the
	// data

	TextView p1;
	TextView p2;
	TextView p3;
	TextView p4;
	TextView p5;
	TextView p6;
	TextView p7;
	TextView p8;
	TextView p9;
	TextView p10;
	TextView p11;
	TextView p12;
	TextView p13;
	TextView p14;
	TextView p15;
	TextView p16;
	TextView p17;
	TextView p18;
	TextView p19;
	TextView p20;
	TextView p21;
	TextView p22;
	TextView p23;
	TextView p24;
	TextView p25;
	TextView p26;
	TextView p27;

	private ArrayList<Presentation> presentations;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		/*
		 * String[] speakers = getResources().getStringArray(R.array.speaker);
		 * String[] names = getResources().getStringArray(
		 * R.array.presentation_name); String[] abstracts =
		 * getResources().getStringArray( R.array.presentation_abstract);
		 * String[] datetimes = getResources().getStringArray(
		 * R.array.presentation_date_time);
		 */

		presentations = DataHelper.getPresentations();

		getViewHandles();
		bindClickListeners();
	}

	@Override
	public void onResume() {
		super.onResume();
		resetClickedViews();
	}

	private void resetClickedViews() {
		// hack to restore original background color of any "clicked" views
		p1.setBackgroundResource(R.color.ltblue);
		p2.setBackgroundResource(R.color.ltblue);
		p3.setBackgroundResource(R.color.ltblue);
		p4.setBackgroundResource(R.color.ltblue);
		p5.setBackgroundResource(R.color.ltblue);
		p6.setBackgroundResource(R.color.ltblue);
		p7.setBackgroundResource(R.color.ltblue);
		p8.setBackgroundResource(R.color.ltblue);
		p9.setBackgroundResource(R.color.ltblue);
		p10.setBackgroundResource(R.color.ltblue);
		p11.setBackgroundResource(R.color.ltblue);
		p12.setBackgroundResource(R.color.ltblue);
		p13.setBackgroundResource(R.color.ltblue);
		p14.setBackgroundResource(R.color.ltblue);
		p15.setBackgroundResource(R.color.ltblue);
		p16.setBackgroundResource(R.color.ltblue);
		p17.setBackgroundResource(R.color.ltblue);
		p18.setBackgroundResource(R.color.ltblue);
		p19.setBackgroundResource(R.color.ltblue);
		p20.setBackgroundResource(R.color.ltblue);
		p21.setBackgroundResource(R.color.ltblue);
		p22.setBackgroundResource(R.color.ltblue);
		p23.setBackgroundResource(R.color.ltblue);
		p24.setBackgroundResource(R.color.ltblue);
		p25.setBackgroundResource(R.color.ltblue);
		p26.setBackgroundResource(R.color.ltblue);
		p27.setBackgroundResource(R.color.ltblue);
	}

	private void getViewHandles() {
		p1 = (TextView) findViewById(R.id.p1);
		p2 = (TextView) findViewById(R.id.p2);
		p3 = (TextView) findViewById(R.id.p3);
		p4 = (TextView) findViewById(R.id.p4);
		p5 = (TextView) findViewById(R.id.p5);
		p6 = (TextView) findViewById(R.id.p6);
		p7 = (TextView) findViewById(R.id.p7);
		p8 = (TextView) findViewById(R.id.p8);
		p9 = (TextView) findViewById(R.id.p9);
		p10 = (TextView) findViewById(R.id.p10);
		p11 = (TextView) findViewById(R.id.p11);
		p12 = (TextView) findViewById(R.id.p12);
		p13 = (TextView) findViewById(R.id.p13);
		p14 = (TextView) findViewById(R.id.p14);
		p15 = (TextView) findViewById(R.id.p15);
		p16 = (TextView) findViewById(R.id.p16);
		p17 = (TextView) findViewById(R.id.p17);
		p18 = (TextView) findViewById(R.id.p18);
		p19 = (TextView) findViewById(R.id.p19);
		p20 = (TextView) findViewById(R.id.p20);
		p21 = (TextView) findViewById(R.id.p21);
		p22 = (TextView) findViewById(R.id.p22);
		p23 = (TextView) findViewById(R.id.p23);
		p24 = (TextView) findViewById(R.id.p24);
		p25 = (TextView) findViewById(R.id.p25);
		p26 = (TextView) findViewById(R.id.p26);
		p27 = (TextView) findViewById(R.id.p27);
	}

	private void bindClickListeners() {
		p1.setOnClickListener(this);
		p2.setOnClickListener(this);
		p3.setOnClickListener(this);
		p4.setOnClickListener(this);
		p5.setOnClickListener(this);
		p6.setOnClickListener(this);
		p7.setOnClickListener(this);
		p8.setOnClickListener(this);
		p9.setOnClickListener(this);
		p10.setOnClickListener(this);
		p11.setOnClickListener(this);
		p12.setOnClickListener(this);
		p13.setOnClickListener(this);
		p14.setOnClickListener(this);
		p15.setOnClickListener(this);
		p16.setOnClickListener(this);
		p17.setOnClickListener(this);
		p18.setOnClickListener(this);
		p19.setOnClickListener(this);
		p20.setOnClickListener(this);
		p21.setOnClickListener(this);
		p22.setOnClickListener(this);
		p23.setOnClickListener(this);
		p24.setOnClickListener(this);
		p25.setOnClickListener(this);
		p26.setOnClickListener(this);
		p27.setOnClickListener(this);
	}

	public void onClick(View v) {
		Intent intent = new Intent(OldMain.this, PresentationDetail.class);
		switch (v.getId()) {
		case R.id.p1:
			populateIntent(intent, 0);
			performIntent(intent, v);
			break;
		case R.id.p2:
			populateIntent(intent, 1);
			performIntent(intent, v);
			break;
		case R.id.p3:
			populateIntent(intent, 2);
			performIntent(intent, v);
			break;
		case R.id.p4:
			populateIntent(intent, 3);
			performIntent(intent, v);
			break;
		case R.id.p5:
			populateIntent(intent, 4);
			performIntent(intent, v);
			break;
		case R.id.p6:
			populateIntent(intent, 5);
			performIntent(intent, v);
			break;
		case R.id.p7:
			populateIntent(intent, 6);
			performIntent(intent, v);
			break;
		case R.id.p8:
			populateIntent(intent, 7);
			performIntent(intent, v);
			break;
		case R.id.p9:
			populateIntent(intent, 8);
			performIntent(intent, v);
			break;
		case R.id.p10:
			populateIntent(intent, 9);
			performIntent(intent, v);
			break;
		case R.id.p11:
			populateIntent(intent, 10);
			performIntent(intent, v);
			break;
		case R.id.p12:
			populateIntent(intent, 11);
			performIntent(intent, v);
			break;
		case R.id.p13:
			populateIntent(intent, 12);
			performIntent(intent, v);
			break;
		case R.id.p14:
			populateIntent(intent, 13);
			performIntent(intent, v);
			break;
		case R.id.p15:
			populateIntent(intent, 14);
			performIntent(intent, v);
			break;
		case R.id.p16:
			populateIntent(intent, 15);
			performIntent(intent, v);
			break;
		case R.id.p17:
			populateIntent(intent, 16);
			performIntent(intent, v);
			break;
		case R.id.p18:
			populateIntent(intent, 17);
			performIntent(intent, v);
			break;
		case R.id.p19:
			populateIntent(intent, 18);
			performIntent(intent, v);
			break;
		case R.id.p20:
			populateIntent(intent, 19);
			performIntent(intent, v);
			break;
		case R.id.p21:
			populateIntent(intent, 20);
			performIntent(intent, v);
			break;
		case R.id.p22:
			populateIntent(intent, 21);
			performIntent(intent, v);
			break;
		case R.id.p23:
			populateIntent(intent, 22);
			performIntent(intent, v);
			break;
		case R.id.p24:
			populateIntent(intent, 23);
			performIntent(intent, v);
			break;
		case R.id.p25:
			populateIntent(intent, 24);
			performIntent(intent, v);
			break;
		case R.id.p26:
			populateIntent(intent, 25);
			performIntent(intent, v);
			break;
		case R.id.p27:
			populateIntent(intent, 26);
			performIntent(intent, v);
			break;
		}
	}

	private void populateIntent(Intent intent, int index) {
		intent.putExtra(Constants.PRES_NAME, presentations.get(index).title);
		intent.putExtra(Constants.PRES_ABSTRACT,
				presentations.get(index).description);
		intent.putExtra(
				Constants.SPEAKER,
				presentations.get(index).speaker.fName + " "
						+ presentations.get(index).speaker.lName);
		// /intent.putExtra(Constants.DATETIME,
		// presentations.get(index).datetime);
	}

	private void performIntent(Intent intent, View v) {
		vibe.vibrate(50);
		// make sure you setBackgroundResource if you refer to a resource (not
		// setBackgroundColor)
		v.setBackgroundResource(R.color.orange);
		startActivity(intent);
	}
}